package com.base.self.controller;

import com.base.log.LoginAn;
import com.base.result.ResponseResult;
import com.base.self.dto.slideshow.ShowSlideshowDTO;
import com.base.self.dto.slideshow.SlideshowWebAddDTO;
import com.base.self.dto.slideshow.SlideshowWebDelDTO;
import com.base.self.dto.slideshow.SlideshowWebListDTO;
import com.base.self.service.ISlideshowService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;

/**
 * <p>
 *  首页轮播图 前端控制器
 * </p>
 *
 * @author XiFYuW
 * @since 2020-11-17
 */
@RestController
@RequestMapping("/admin/slideshow")
public class SlideshowController {

    private final ISlideshowService iSlideshowService;

    public SlideshowController(ISlideshowService iSlideshowService) {
        this.iSlideshowService = iSlideshowService;
    }

    @GetMapping(value = "/slideshowIndex")
    @LoginAn
    public ModelAndView slideshowIndex() {
        return new ModelAndView("self/index_slideshow");
    }

    @PostMapping(value = "/slideshowWebList")
    @Validated
    @LoginAn(isRe = true)
    public ResponseResult slideshowWebList(@Valid final SlideshowWebListDTO slideshowWebListDTO) {
        return iSlideshowService.slideshowWebList(slideshowWebListDTO);
    }

    @PostMapping(value = "/slideshowWebAdd")
    @Validated
    @LoginAn(isRe = true)
    public ResponseResult slideshowWebAdd(@Valid final SlideshowWebAddDTO slideshowWebAddDTO) {
        return iSlideshowService.slideshowWebAdd(slideshowWebAddDTO);
    }

    @PostMapping(value = "/slideshowWebDel")
    @Validated
    @LoginAn(isRe = true)
    public ResponseResult slideshowWebDel(@Valid final SlideshowWebDelDTO slideshowWebDelDTO) {
        return iSlideshowService.slideshowWebDel(slideshowWebDelDTO);
    }

    @PostMapping(value = "/showSlideshow")
    @Validated
    @LoginAn(isRe = true)
    public ResponseResult showSlideshow(@Valid final ShowSlideshowDTO showSlideshowDTO) {
        return iSlideshowService.showSlideshow(showSlideshowDTO);
    }
}

